#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3e4 + 5;

int n, m, k = 1;
int a[N], b[N];
priority_queue<int> mn;
priority_queue<int, vector<int>, greater<int>> mx;
void adjust() {
  while (mn.size() < k) {
    int x = mx.top();
    mx.pop();
    mn.push(x);
  }
  while (mn.size() > k) {
    int x = mn.top();
    mn.pop();
    mx.push(x);
  }
}
void insert(int x) {
  if (mx.size() && mx.top() <= x)
    mx.push(x);
  else
    mn.push(x);
  adjust();
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, m) cin >> b[i];
  int i = 1;
  rep(j, 1, m) {
    k = j;
    while (i <= b[j]) insert(a[i++]);
    adjust();
    cout << mn.top() << endl;
  }
  return 0;
}